import {Form, Field} from  './../../rsuite/rsuite-form';
import {
    Radio,
    Button, Row, Col, Grid, FormControl, ControlLabel, RadioList, HelpBlock,
    TextList, Dropdown, CheckboxList, Checkbox, InputGroup, Modal, FormGroup
} from  './../../rsuite';
import {SchemaModel, StringType, ArrayType} from './../../rsuite/schema';

const MyModel = SchemaModel({
    name: StringType().isRequired('该字段必填'),
    desc: StringType().isRequired('该字段必填'),
});

export default React.createClass({
    PropTypes: {
        errors: React.PropTypes.obejct,
        message: React.PropTypes.string,
        data: React.PropTypes.data
    },
    getInitialState() {
        return {
            submiting: '',
            data: {desc: '', name: ''}
        };
    },

    //submit form data
    handleSubmit() {
        const form = this.refs.myForm.get();

        if (!form.isValid) {
            return;
        }

        if (this.state.submiting.length)return;

        this.setState({submiting: '....'})
        const self = this;
        ///submit form
        // setTimeout(function () {
        //     self.setState({submiting: ''})
        //     self.props.onFinised(form.formData);
        // }, 2000)
        //

    },
    valueChange(e){
        console.log(e)
    },
    render() {
        return (
            <div className="">
                <Form ref="myForm"
                      model={MyModel}
                      errors={this.props.errors}
                      formData={this.state.data}
                >
                    <Field name="name">
                        <FormGroup>
                            <ControlLabel>分类名称</ControlLabel>
                            <FormControl type='text'/>
                            <HelpBlock>必填</HelpBlock>
                        </FormGroup>
                    </Field>
                    <Field name="desc">
                        <FormGroup>
                            <ControlLabel>分类描述</ControlLabel>
                            <FormControl type='text'/>
                            <HelpBlock>必填</HelpBlock>
                        </FormGroup>
                    </Field>
                    <Button shape="primary" onClick={this.handleSubmit}>提交{this.state.submiting}</Button>
                </Form>

            </div>
        );
    }
});
